{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2e20101d",
   "metadata": {},
   "source": [
    "________________\n",
    "\n",
    "* 2022/10/17/week09\n",
    "* Python学习记录\n",
    "_________________"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a845b3a1",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1.用户输入\n",
    "\n",
    "> 2.文本的格式化输出\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8de87f4",
   "metadata": {},
   "source": [
    "## 1. 用户输入\n",
    "\n",
    "* input方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "962a9023",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "# 用户登陆系统\n",
    "username = input()\n",
    "password = input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ac98edf4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "32599294",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n"
     ]
    }
   ],
   "source": [
    "username = input(\"账号：\")\n",
    "password = input(\"密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fbe56cf8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: ndfsddd\n",
      "密码: 1234\n",
      "账号不存在或密码不正确\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号: \")\n",
    "password = input(\"密码: \")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and password01 == password:\n",
    "    print(\"登陆成功~欢迎\"+user01)\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f9a6ba13",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: admin\n",
      "密码: 123456\n",
      "登陆成功~欢迎admin\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号: \")\n",
    "password = input(\"密码: \")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and password01 == password:\n",
    "    print(\"登陆成功~欢迎\"+user01)\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d48692d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: nfuww\n",
      "密码: 22222\n",
      "账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
      "username = input(\"账号: \")\n",
      "password = input(\"密码: \")\n",
      "username = input(\"账号: \")\n",
      "password = input(\"密码: \")\n",
      "username = input(\"账号: \")\n",
      "password = input(\"密码: \")\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环！ for + range()\n",
    "\n",
    "\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号: \")\n",
    "password = input(\"密码: \")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and password01 == password:\n",
    "    print(\"登陆成功~欢迎\"+user01)\n",
    "# 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\")\n",
    "    for num in range(3):\n",
    "        print('username = input(\"账号: \")')\n",
    "        print('password = input(\"密码: \")')\n",
    "\n",
    "\n",
    "    \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "00a4d87a",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [16]\u001b[0m, in \u001b[0;36m<cell line: 4>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m user01 \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124madmin\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m      2\u001b[0m password01 \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m123456\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 4\u001b[0m username \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m账号: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      5\u001b[0m password \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m密码: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      6\u001b[0m \u001b[38;5;66;03m# 情景一：账号密码都正确\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号: \")\n",
    "password = input(\"密码: \")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and password01 == password:\n",
    "    print(\"登陆成功~欢迎\"+user01)\n",
    "# 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\")\n",
    "    for num in range(3):\n",
    "        username = input(\"账号: \")\n",
    "        password = input(\"密码: \")\n",
    "      \n",
    "\n",
    "        \n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "79bc09dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: gsd\n",
      "密码: 432\n",
      "账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
      "账号: gfsd\n",
      "密码: 333\n",
      "账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
      "账号: fffff\n",
      "密码: 2323\n",
      "账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3):\n",
    "    username = input(\"账号: \")\n",
    "    password = input(\"密码: \")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "    # 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        print(\"账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4253c4f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: dfddf\n",
      "密码: 22222\n",
      "账号不存在或密码不正确!请重新输入!您还有2尝试的机会\n",
      "账号: dffggg\n",
      "密码: 44444\n",
      "账号不存在或密码不正确!请重新输入!您还有1尝试的机会\n",
      "账号: ggg\n",
      "密码: 3333\n",
      "账号不存在或密码不正确!请重新输入!您还有0尝试的机会\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号: \")\n",
    "    password = input(\"密码: \")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "    # 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        print(\"账号不存在或密码不正确!请重新输入!您还有\"+str(i-1)+\"尝试的机会\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "059ea412",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: ddddd\n",
      "密码: 33333\n",
      "账号不存在或密码不正确!请重新输入!您还有2尝试的机会\n",
      "账号: 3333\n",
      "密码: 22222\n",
      "账号不存在或密码不正确!请重新输入!您还有1尝试的机会\n",
      "账号: 33333\n",
      "密码: 555555\n",
      "账号不存在或密码不正确!请1小时后再来尝试!\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号: \")\n",
    "    password = input(\"密码: \")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "    # 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确!请重新输入!您还有\"+str(i-1)+\"尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确!请1小时后再来尝试!\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9892032d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: admin\n",
      "密码: 123456\n",
      "登陆成功~欢迎admin\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [24]\u001b[0m, in \u001b[0;36m<cell line: 4>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      2\u001b[0m password01 \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m123456\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m):\n\u001b[1;32m----> 5\u001b[0m     username \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m账号: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      6\u001b[0m     password \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m密码: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      7\u001b[0m     \u001b[38;5;66;03m# 情景一：账号密码都正确\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号: \")\n",
    "    password = input(\"密码: \")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "    # 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确!请重新输入!您还有\"+str(i-1)+\"尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确!请1小时后再来尝试!\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "21f4f963",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: admin\n",
      "密码: 123456\n",
      "登陆成功~欢迎admin\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号: \")\n",
    "    password = input(\"密码: \")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "        break # 中止循环\n",
    "    # 情景二：账号不存在或密码不正确,用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确!请重新输入!您还有\"+str(i-1)+\"尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确!请1小时后再来尝试!\")\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "411bff47",
   "metadata": {},
   "source": [
    "## 2.字符串的格式化输出\n",
    "\n",
    ">1. 字符串的拼接\n",
    ">2. 占位符\n",
    ">3. 格式化输出的方法：format（）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c97dd2d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称: 李华\n",
      "地区: 深圳\n",
      "工作: 产品经理助理\n",
      "年龄: 22\n",
      "期待薪资: 10K/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）\n",
    "name = input(\"昵称: \")\n",
    "region = input(\"地区: \")\n",
    "job = input(\"工作: \")\n",
    "age = input(\"年龄: \")\n",
    "salary = input(\"期待薪资: \")\n",
    "\n",
    "info = '''------------INFO '''+ name + '''-----------\n",
    "地区: '''+ region + '''\n",
    "工作: '''+ job + '''\n",
    "年龄: '''+ age + '''\n",
    "薪资期待: '''+salary\n",
    "# 好麻烦，好容易出错！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "98952cc0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------------INFO 李华-----------\n",
      "地区: 深圳\n",
      "工作: 产品经理助理\n",
      "年龄: 22\n",
      "薪资期待: 10K/月\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "8ff173d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称: 李华\n",
      "地区: 广州\n",
      "工作: 前端开发\n",
      "年龄: 22\n",
      "期待薪资: 15\n",
      "-----------INFO 李华 --------\n",
      "地区: 广州\n",
      "工作: 前端开发\n",
      "年龄: 22\n",
      "薪资期待: 15 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） ：format()\n",
    "name = input(\"昵称: \")\n",
    "region = input(\"地区: \")\n",
    "job = input(\"工作: \")\n",
    "age = input(\"年龄: \")\n",
    "salary = input(\"期待薪资: \")\n",
    "\n",
    "info = '''-----------INFO %s --------\n",
    "地区: %s\n",
    "工作: %s\n",
    "年龄: %s\n",
    "薪资期待: %s '''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "b8090d34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称: 李华\n",
      "地区: 深圳\n",
      "工作: python\n",
      "年龄: 22\n",
      "期待薪资: 18K/月\n",
      "-----------INFO 李华 --------\n",
      "地区: 深圳\n",
      "工作: python\n",
      "年龄: 22\n",
      "薪资期待: 18K/月 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） ：format() \n",
    "name = input(\"昵称: \")\n",
    "region = input(\"地区: \")\n",
    "job = input(\"工作: \")\n",
    "age = input(\"年龄: \")\n",
    "salary = input(\"期待薪资: \")\n",
    "\n",
    "info = '''-----------INFO {昵称} --------\n",
    "地区: {地区}\n",
    "工作: {工作职位}\n",
    "年龄: {年龄}\n",
    "薪资期待: {薪资} '''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "# 书写规范，字符串中的字段一一对应，不考虑其顺序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "cfc73793",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称: 李华\n",
      "地区: 广州\n",
      "工作: 用户增长\n",
      "年龄: 22\n",
      "期待薪资: 15K\n",
      "-----------INFO 李华 --------\n",
      "地区: 用户增长\n",
      "工作: 广州\n",
      "年龄: 22\n",
      "薪资期待: 15K \n"
     ]
    }
   ],
   "source": [
    "name = input(\"昵称: \")\n",
    "region = input(\"地区: \")\n",
    "job = input(\"工作: \")\n",
    "age = input(\"年龄: \")\n",
    "salary = input(\"期待薪资: \")\n",
    "\n",
    "info = '''-----------INFO %s --------\n",
    "地区: %s\n",
    "工作: %s\n",
    "年龄: %s\n",
    "薪资期待: %s '''%(name,job,region,age,salary)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7399d4e4",
   "metadata": {},
   "source": [
    "## 课后作业 :\n",
    "> 1.第二章P93前所有项目内容（下周讲）\n",
    "> 2.购物车项目\n",
    ">>要求：\n",
    ">>> 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">>> 2. 让用户输入商品编号进行商品的购买。\n",
    ">>> 3. 让用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    ">>> 4. 用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e9b7a9f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
